	
	
		var playList = [];
		var chapterIndex = GetQueryString('chapter');
		template.defaults.imports.chapterIndex = chapterIndex;
		template.defaults.imports.addUrl = function(value){return imgHosturl+value};
		var audioData = null;
		var totalChapterCount = null;
	
		function changeIndex(x){
		  	chapterIndex += x;
//		  	document.querySelector('#audio').pause();
		  	if(chapterIndex<0){
		  		chapterIndex = 0;
		  	}
		  	if(chapterIndex>totalChapterCount-1){
		  		chapterIndex = totalChapterCount-1
		  	}
	  		template.defaults.imports.chapterIndex = chapterIndex;
			render(audioData);
			afterAjax();
			$(".f-l").text('00:00');
		}
		function afterAjax(){
			$("audio").get(0).load();

	        var oAudio=document.querySelector('#audio');
	        var oDiv1=document.querySelector('#box');
	        var oDiv2=document.querySelector('#strip');
	        var oDiv3=document.querySelector('#circel');
	        var oPlay=document.querySelector('#play');
	        var timer='';
	
			
	          oPlay.onclick=function(){
	              if(oAudio.paused){
	                  oAudio.play();
	                  $("#play img").attr('src','icon/ic_voice_pause_big663.png')
	                  $('.f-r').text(formatSeconds(oAudio.duration))
	                  $(oPlay).removeClass('toPlay').addClass('toPause')
	                  timer=setInterval(function(){
	                      if(oAudio.paused){
	                          clearInterval(timer)
	                          $(oPlay).removeClass('toPause').addClass('toPlay');
	                          clearInterval(timer)
	                      }
	                      playAudio(oAudio.currentTime/oAudio.duration)
	                      // vm.voteTime = oAudio.duration-oAudio.currentTime;
	                      $('.f-l').text(formatSeconds(oAudio.currentTime))
	                  }, 100)
	              }else{
	                  oAudio.pause();
	                  $("#play img").attr('src','icon/ic_daily_note_play66.png')
	                  $(oPlay).removeClass('toPause').addClass('toPlay');
	                  clearInterval(timer)
	              }
	          }
	          function playAudio(iNow){
	              oDiv2.style.width=iNow*100+'%';
	              oDiv3.style.left=iNow*100+'%';
	          }
	
	          oDiv3.addEventListener('touchstart',function(ev){
	              clearInterval(timer)
	              var oDiv1W = oDiv1.offsetWidth;
	              var oldX = ev.targetTouches[0].clientX - oDiv3.offsetLeft;
	
	              document.addEventListener('touchmove',fnMove,false)
	              document.addEventListener('touchend',fnEnd,false)
	              function fnMove(ev){
	
	                  var x = ev.targetTouches[0].clientX - oldX;
	                  if(x>=oDiv1W){
	                      x=oDiv1W;
	                  }else if(x<=0){
	                      x=0;
	                  }
	                  oDiv3.style.left=x+'px';
	                  oDiv2.style.width=x+'px';
	
	              }
	              function fnEnd(ev){
	                  document.removeEventListener('touchend',fnEnd,false)
	                  document.removeEventListener('touchmove',fnMove,false)
	                  var newX = ev.changedTouches[0].clientX;
	                  var oDiv2W = oDiv2.offsetWidth;
	                  var oDuration = oDiv2W/oDiv1W;
	                  clearInterval(timer)
	
	                  oAudio.currentTime=oDuration*oAudio.duration;
	                  timer=setInterval(function(){
	                      if(oAudio.paused){
	                          clearInterval(timer)
	                          $(oPlay).removeClass('toPause').addClass('toPlay');
	                          clearInterval(timer)
	                      }
	                      playAudio(oAudio.currentTime/oAudio.duration)
	                      $('.f-l').text(formatSeconds(oAudio.currentTime))
	                  }, 100)
	
	              }
	          },false);
		}
		function render(data){
			var html = template("player_tem",data);
			document.getElementById('content').innerHTML = html;
		};
		
		  $(function(){
			var bookoddid = GetQueryString("bookoddid"),index = GetQueryString("index")
			var bookid=GetQueryString("bookid");
			$.ajax({
				type:"get",
				url:ascli(hostUrl+"bookreading/detail?token="+token+"&bookid="+bookid)+"&copywriter=0&videoauthor=0",
				async:true,
				success:function(data){
					audioData = data;
					totalChapterCount = data.data.chaptercount;
//					$("audio").off('loadedmetadata').on("loadedmetadata",function(){
//			            $("audio").get(0).play();
//			        });
				
					var html = template("player_tem",data);
					document.getElementById('content').innerHTML = html;
					afterAjax();
				}
			});
			
			$("#back").click(function(){
				if(!!window.android){
					window.android.finish();
				}else{
					window.location.href = "billboard.html";
				}
			});
			
			//分享的弹出
			$("#share").on('click',function(){
	  			$("#sharemask").show();
		  		setTimeout(function(){
		  			$("#tran").css({
			  			'transform': 'translate3d(0,-100%,0)'
			  		});
		  		},10)
		  	})
			$("#cancel").on('click',function(){

		  		$("#tran").css({
		  			'transform': 'translate3d(0,0,0)'
		  		});
		  		setTimeout(function(){
		  			$("#sharemask").hide();
		  		},500)
		  	})
		    
		   
		    
		    
		  })
		
		  	
		  
		 
		 

	




		
